package com.example.springmvcuse;

public class Sort {

    public static void insertSort(int[] array){
        // write code  here
        for (int i = 1; i < array.length; i++) {
            int j = i-1;
            int tmp = array[i];
            for (; j >=0 ; j--) {
                if(array[j]>tmp){
                    array[j+1]=array[j];
                }else {
                    break;
                }

            }
            array[j+1]=tmp;
        }

    }


        // 希尔排序
        public static void shellSort(int[] array){
        // write code  here
            int n = array.length;
            for(int gap = n/2;gap>0;gap/=2){
                for (int i = gap; i < array.length; i++) {
                    int j = i-gap;
                    int tmp = array[i];
                    for (; j >=0 ; j-=gap) {
                        if(array[j]>tmp){
                            array[j+gap]=array[j];
                        }else {
                            break;
                        }

                    }
                    array[j+gap]=tmp;
                }
            }



    }
}
